package kaumono.util;

import java.util.Set;

import susano.common.util.BeanMap;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;

/**
 * BeanMapユーティル
 *
 * @author tanaka.akira
 * @version $Id: BeanMapUtil.java 687 2009-11-13 07:55:17Z tanaka.akira.2006 $
 */
public final class BeanMapUtil {

	/**
	 * {@link BeanMap} から親エンティティを生成
	 *
	 * @param bm
	 *            {@link BeanMap}
	 * @param key
	 *            {@link Key}
	 * @return {@link Entity}
	 */
	public static Entity createRootEntity(final BeanMap bm, final Key key) {
		Entity entity = new Entity(key);
		Set<String> mapkeys = bm.keySet();
		for (String mapkey : mapkeys) {
			if (mapkey.equals(Entity.KEY_RESERVED_PROPERTY)) {
				continue;
			}
			Object mapvalue = bm.get(mapkey);
			entity.setProperty(mapkey, mapvalue);
		}
		return entity;
	}

}
